#include "include.h"
#include "config.h"
#include "systick.h"
#include "uart.h"
#include "motor.h"

#define MOTOR1 P07
#define motor2 P06
#define motor3 P05
#define motor4 P04

static bit on_flag = 0;
static uint16_t step_time;

static uint16_t speed_time;


void set_motor_run(void){
	//on_flag = status;
	if(__CF_FLAME_SPEED == 1)      speed_time = 50;
	else if(__CF_FLAME_SPEED == 2) speed_time = 40;
	else if(__CF_FLAME_SPEED == 3) speed_time = 30;
	else if(__CF_FLAME_SPEED == 4) speed_time = 20;
	else if(__CF_FLAME_SPEED == 5) speed_time = 10;
	
	if(!__CF_POWER || !__CF_FLAME_POWER){
		on_flag = 0;
	}
	else{
		on_flag = 1;
	}
}

static uint8_t step = 0;

void motor_func(void){
	set_motor_run();
	if(on_flag){
		if(1){
				++step;
        if(step > 7) step = 0;

        switch(step){
#if 1
					case 7:
						STEP01A();
						break;
					case 6:
						STEP01AB(); 
						break;
					case 5:
						STEP01B();
						break;
					case 4:
						STEP01BC();
						break;
					case 3:
						STEP01C();
						break;
					case 2:
						STEP01CD();
						break;
					case 1:
						STEP01D();
						break;
					case 0:
						STEP01DA();
						break;
#else
					case 0:
						STEP01A();
						break;
					case 1:
						STEP01AB(); 
						break;
					case 2:
						STEP01B();
						break;
					case 3:
						STEP01BC();
						break;
					case 4:
						STEP01C();
						break;
					case 5:
						STEP01CD();
						break;
					case 6:
						STEP01D();
						break;
					case 7:
						STEP01DA();
						break;
#endif
					default:
						break;
        }
				reset_time(&step_time);
			}
	}
	else{
		MOTOR01_A = 0;
		MOTOR01_B = 0;
		MOTOR01_C = 0;
		MOTOR01_D = 0;
	}
}



